package com.itheima.service.impl;

import com.itheima.dao.UserMemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private UserMemberDao userMemberDao;

    /**
     * 用户登录
     * @param telephone
     * @return
     */
    @Override
    public Integer login(String telephone) {
        Integer recordCount = 0;
        Member member = userMemberDao.findByPhoneNumber(telephone);
        if (member == null){
            // 当期用户不存在，自动注册
            Member member1 = new Member();
            member1.setPhoneNumber(telephone);
            member1.setRegTime(new Date());

            recordCount = userMemberDao.add(member1);
        }

        return recordCount;
    }
}
